from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

browser = webdriver.Chrome();
try: 
    browser.get("https://www.baidu.com")
    input = browser.find_element_by_id("kw")
    input.send_keys('Python')
    wait = WebDriverWait(browser, 10)
    wait.until(EC.presence_of_element_located((By.ID, 'wrapper')))
    print(browser.current_url)
    baidu_handle = browser.current_window_handle
    js = 'window.open("{}");'.format('https://gitee.com')
    browser.execute_script(js)
    browser.switch_to.window(baidu_handle)
    handles = browser.window_handles
    browser.switch_to.window(handles[-1])
    print(browser.current_url)
finally:
    browser.close()